# -*- coding:utf-8 -*-
import Tkinter

from controller import Controller
from engine import Engine
import settings
class PachongWin(object):
    def run(self):
        self.root=Tkinter.Tk()
        title='%s爬虫控制窗口'%settings.S_target_website
        self.root.title(title)
        
        #画界面
        self.root.geometry('190x80')
        self.f = Tkinter.Frame(self.root)
        self.b_start=Tkinter.Button(self.f,text='启动',command=self.start)
        self.b_start.config(height=3,width=10)
        self.b_start.pack()
        self.b_stop=Tkinter.Button(self.f,text='退出',state=Tkinter.DISABLED,command=self.stop)
        self.b_stop.config(height=3,width=10)
        self.b_stop.pack()
        self.f.pack()
            
        Tkinter.mainloop()
        
    def start(self):
        self.controller=Controller()
        self.controller.start()
        self.b_start.config(state=Tkinter.DISABLED)
        while not self.controller.engine_is_running:
            pass
        self.b_stop.config(state=Tkinter.ACTIVE)        
        
    def stop(self):
        self.controller.stop()
        self.b_stop.config(state=Tkinter.DISABLED)
        while True:
            t_list=[t for t in self.controller.eng.threads if t.is_running==False]
            if len(t_list)==len(self.controller.eng.threads):
                break;
        self.b_start.config(state=Tkinter.ACTIVE)
        
if __name__=='__main__':
    win=PachongWin()
    win.run()




    
    
    
    
    
    
    
    
    
    


